import java.util.stream.IntStream;

public class LeetCode2682 {


    // 5 2
    public int[] circularGameLosers(int n, int k) {
        int lcm = lcm(n, k);
        int[] range = IntStream.range(1, n + 1).toArray();
        int current = 0;
        range[1] = 0;
        for (int i = 1; i <= lcm / k; i++) {
            current += k * i;
            current %= n;
            range[current] = 0;
        }

        int size = 0;
        for (int r : range) {
            if (r != 0) {
                size++;
            }
        }

        int i = 0;
        int[] res = new int[size];
        for (int r : range) {
            if (r != 0) {
                res[i++] = r;
            }
        }

        return res;
    }

    private int gcd(int a, int b) {
        return a == 0 ? b : gcd(b % a, a);
    }

    public int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }
    //file__0.indexeddb.leveldb/

}
